package com.metaera.app.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.metaera.app.R;
import com.metaera.app.ui.core.BaseActivity;
import com.metaera.app.utils.ActivityTitleHelper;

public class NotifyDetailsActivity extends BaseActivity {

    public static final String EXTRA_CONTENT = "EXTRA_CONTENT";

    public static Intent newIntent(Context context, String title, String content) {
        return new Intent(context, NotifyDetailsActivity.class)
                .putExtra(NotifyDetailsActivity.EXTRA_CONTENT, content)
                .putExtra("EXTRA_TITLE", title);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_notify_details;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        // find
        WebView webView = findViewById(R.id.web_view);
        TextView tvTitle = findViewById(R.id.tv_big_title);

        // init
        ActivityTitleHelper.setTitle(this, R.string.notify_details, R.string.home_more);
        tvTitle.setText(getIntent().getStringExtra("EXTRA_TITLE"));
        String content = getIntent().getStringExtra(NotifyDetailsActivity.EXTRA_CONTENT);

        // html
        webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.getSettings().setSupportZoom(false);
        webView.loadData(getHtmlData(content), "text/html", "UTF-8");
        webView.loadDataWithBaseURL(null, getHtmlData(content), "text/html", "UTF-8", null);

        // listener
        findViewById(R.id.tv_action).setOnClickListener(v -> startActivity(NoticeListActivity.class));
    }

    private String getHtmlData(String bodyHTML) {
        String head = "<head>"
                + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
                + "<style>img{max-width: 100%; width:100%; height:auto;}*{margin:0px;}</style>"
                + "</head>";
        return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
    }

}
